local jjj__yeyan = fk.CreateSkill {

  name = "jjj__yeyan&",

  tags = { Skill.Limited, },

}



jjj__yeyan:addEffect("active", {
  name = "jjj__yeyan&",
  anim_type = "offensive",
  min_target_num = 1,
  max_target_num = 3,
  min_card_num = 0,
  max_card_num = 4,
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(jjj__yeyan.name, Player.HistoryGame) == 0
  end,
  card_filter = function(self, player, to_select, selected)
    return table.contains(player.player_cards[Player.Hand], to_select) and not player:prohibitDiscard(Fk:getCardById(to_select))
    and table.every(selected, function (id) return Fk:getCardById(to_select).suit ~= Fk:getCardById(id).suit end)
  end,
  target_filter = function(self, player, to_select, selected)
    if #selected_cards == 4 then
      return #selected < 2
    elseif #selected_cards == 0 then
      return #selected < 3
    else
      return false
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local damageMap = {}
    if #effect.cards == 0 then
      for _, pid in ipairs(effect.tos) do
        damageMap[pid] = 1
      end
    else
      if #effect.tos == 1 then
        local choice = room:askForChoice(player, {"3", "2"}, jjj__yeyan.name)
        damageMap[effect.tos[1]] = tonumber(choice)
      else
        local tos = room:askForChoosePlayers(player, effect.tos, 1, 1, "#yeyan-choose", jjj__yeyan.name, false)
        damageMap[tos[1]] = 2
        damageMap[tos[1] == effect.tos[1] and effect.tos[2] or effect.tos[1]] = 1
      end
      room:throwCard(effect.cards, jjj__yeyan.name, player, player)
      doJianjieMarkChange (room, player, "@@joy__dragon_mark", false, player)
      doJianjieMarkChange (room, player, "@@joy__phoenix_mark", false, player)
    end
    room:sortPlayersByAction(effect.tos)
    for _, pid in ipairs(effect.tos) do
      local to = room:getPlayerById(pid)
      if not to.dead then
        room:damage{
          from = player,
          to = to,
          damage = damageMap[pid],
          damageType = fk.FireDamage,
          skillName = jjj__yeyan.name,
        }
      end
    end
  end,
})

return jjj__yeyan